package ListQueue;


import interfaces.Queue;

import java.util.NoSuchElementException;

public class DLLQueue<E> implements Queue<E> {

    private DoubleLinkedList<E> queuedList;
    private int numberOfElementsInArray;

    public DLLQueue() {

        this.queuedList = new DoubleLinkedList<E>();

    }

    public boolean isEmpty() {

        return numberOfElementsInArray == 0;
    }

    @Override
    public E element() {
        if (isEmpty())
            throw new NoSuchElementException("Queue is empty");
        return queuedList.getFirst();
    }

    @Override
    public boolean offer(E e) {
        queuedList.addLast(e);
        numberOfElementsInArray++;
        return true;
    }

    @Override
    public E peek() {
        if (!isEmpty())
            return queuedList.getFirst();
        return null;
    }

    @Override
    public E poll() {
        if (!isEmpty()) {
            numberOfElementsInArray--;
            return queuedList.removeFirst();
        }
        return null;
    }

    @Override
    public E remove() {
        if (isEmpty()) {
            throw new NoSuchElementException("Queue is empty");
        }
        numberOfElementsInArray--;
        return queuedList.removeFirst();
    }

}
